package tech.lithum.mm.ui.notifications;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import tech.lithum.mm.R;
import tech.lithum.mm.databinding.FragmentNotificationsBinding;

public class NotificationsFragment extends Fragment {

    private FragmentNotificationsBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        NotificationsViewModel notificationsViewModel =
                new ViewModelProvider(this).get(NotificationsViewModel.class);

        binding = FragmentNotificationsBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        final GridLayout gridLayout = binding.myimages;

        List<String> urls = new ArrayList<>();
        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_1.jpg");
        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_2.jpg");
        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_3.jpg");
        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_4.jpg");
        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_5.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_6.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_7.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_8.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_9.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_10.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_11.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_12.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_13.jpg");
//        urls.add("https://imgyagi.top/wp-content/uploads/2024/02/KING3NASH_14.jpg");

        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenW = dm.widthPixels;

        int width = 0;
        switch(urls.size()) {
            case 1:
                gridLayout.setColumnCount(1);
                gridLayout.setRowCount(1);
                width = screenW / 100 * 80;
                break;
            case 2:
                gridLayout.setColumnCount(2);
                gridLayout.setRowCount(1);
                width = screenW / 100 * 40;
                break;
            case 3:
                gridLayout.setColumnCount(3);
                gridLayout.setRowCount(1);
                width = screenW / 100 * 30;
                break;
            case 4:
                gridLayout.setColumnCount(2);
                gridLayout.setRowCount(2);
                width = screenW / 100 * 40;
                break;
            case 5:
            case 6:
                gridLayout.setColumnCount(3);
                gridLayout.setRowCount(2);
                width = screenW / 100 * 30;
                break;
            default:
                gridLayout.setColumnCount(3);
                gridLayout.setRowCount(3);
                width = screenW / 100 * 30;
                break;
        }


        for(int i = 0 ; i < urls.size()  && i <= 9 ; i++) {
            ImageView imageView = new ImageView(getContext());
            gridLayout.addView(imageView, width, 600);
            Picasso.get().load(urls.get(i)).into(imageView);
        }
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}